/**  
 * All rights Reserved, Designed By www.woniuxy.com
 * @Title:  Account.java   
 * @Package com.woniu.domain   
 * @Description:    Description  
 * @author: 蜗牛学院  
 * @date:   2019年10月20日 下午2:56:26
 * @user:   Administrator  
 * @version V1.0 
 * @Copyright: 2019 www.woniuxy.com Inc. All rights reserved. 
 * 注意：本内容仅限于成都蜗牛创想科技有限公司，禁止外泄以及用于其他的商业目
 */ 
package com.moon.controller;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.moon.utils.BaseController;

/**
 * @author Administrator
 *
 */
@Controller
public class UploadController extends BaseController{
	@RequestMapping("/upload")
	@ResponseBody
	public String upload(MultipartFile myfile,HttpServletRequest req) throws IllegalStateException, IOException {
		//每上传一次都会创建一次文件夹存放每次上传的文件
		String webroot = req.getServletContext().getRealPath("");
		System.out.println(webroot);
		File dir = new File(webroot + "\\upload");
		//本地路径
		dir.mkdir();
		System.out.println(dir.getAbsolutePath());
		File file = new File(
				dir.getAbsolutePath()+"\\"+UUID.randomUUID().toString()+"-"+myfile.getOriginalFilename()
				);
		//上传文件
		myfile.transferTo(file);
		return "上传成功";
	}
}
